package demo1;

import java.util.Arrays;

public class Test9 {
    public static void bubble(int[] arr) {
        for (int i = 0; i < arr.length-1; i++) {
            boolean flg = false;
            for (int j = 0; j < arr.length-1-i; j++) {
                if (arr[j] > arr[j+1]) {
                    int tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                    flg = true;
                }
            }
            if (flg == false) {
                break;
            }
        }
    }

    public static void main(String[] args) {
        int[] arr = {8,29,46,1,49,28}; // 1,8,28,    29,   46,  49
        bubble(arr);
        System.out.println(Arrays.toString(arr));
    }

}
